#pragma once

#include <AVUISelector.h>

namespace AVUI {

class TabItem;
class ContentPresenter;


// TODO -- Determine, how does TabPanel get invalidated to recalculate which item is at what level?
class TabControl : public Selector
{
public:
    TabControl() { };
    ~TabControl() { };

    DECLARE_ELEMENT(TabControl, Selector);

    DECLARE_DEPENDENCY_PROPERTY(TabStripPlacement);
    Dock::Enum get_TabStripPlacement() { return (Dock::Enum)(AVUI::UnboxValue<int>(GetValue(get_TabStripPlacementProperty()))); }
    void set_TabStripPlacement(Dock::Enum value) { SetValue(get_TabStripPlacementProperty(), AVUI::BoxValue<int>(value)); } 

    DECLARE_READONLY_DEPENDENCY_PROPERTY(SelectedContent);
    TRefCountedPtr<Object> get_SelectedContent() { return GetValue(get_SelectedContentProperty()); }
    void set_SelectedContent(Object* pValue) { return SetValue(SelectedContentPropertyKey, pValue); }

    DECLARE_READONLY_DEPENDENCY_PROPERTY(SelectedContentTemplate);
    TRefCountedPtr<DataTemplate> get_SelectedContentTemplate() { return (DataTemplate*)(Object*)GetValue(get_SelectedContentTemplateProperty()); }
    void set_SelectedContentTemplate(DataTemplate* pValue) { SetValue(SelectedContentTemplatePropertyKey, (Object*)pValue); } 

    DECLARE_READONLY_DEPENDENCY_PROPERTY(SelectedContentTemplateSelector);
    TRefCountedPtr<DataTemplateSelector> get_SelectedContentTemplateSelector() { return (DataTemplateSelector*)(Object*)GetValue(get_SelectedContentTemplateSelectorProperty()); }
    void set_SelectedContentTemplateSelector(DataTemplateSelector* pValue) { SetValue(SelectedContentTemplateSelectorPropertyKey, (Object*)pValue); } 

    DECLARE_DEPENDENCY_PROPERTY(ContentTemplate);
    TRefCountedPtr<DataTemplate> get_ContentTemplate() { return (DataTemplate*)(Object*)GetValue(get_ContentTemplateProperty()); }
    void set_ContentTemplate(DataTemplate* pValue) { SetValue(get_ContentTemplateProperty(), (Object*)pValue); } 

    DECLARE_DEPENDENCY_PROPERTY(ContentTemplateSelector);
    TRefCountedPtr<DataTemplateSelector> get_ContentTemplateSelector() { return (DataTemplateSelector*)(Object*)GetValue(get_ContentTemplateSelectorProperty()); }
    void set_ContentTemplateSelector(DataTemplateSelector* pValue) { SetValue(get_ContentTemplateSelectorProperty(), (Object*)pValue); } 

protected:

    virtual bool IsItemItsOwnContainerOverride(Object* pItem);
    virtual TRefCountedPtr<DependencyObject> GetContainerForItemOverride();
    virtual void OnApplyTemplate();
    virtual void OnInitialized(EventArgs* pEventArgs);
    virtual void OnSelectionChanged(SelectionChangedEventArgs* pArgs);

private:
    static void StaticConstructor();

    ContentPresenter* get_SelectedContentPresenter();
    void UpdateSelectedContent();
    TabItem* GetSelectedTabItem();
    void OnGeneratorStatusChanged(Object* pSender, EventArgs* e);

     


};

}; // namespace AVUI
